import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("http://121.43.169.97:8848/pageA.html")

"""
需求：打开注册A页面，完成以下操作
python基础). 输入用户名：admin1，暂停2秒，删除1
2). 全选用户名：admin，暂停2秒
3). 复制用户名：admin，暂停2秒
4). 粘贴到密码框
"""
# 定位用户名
element = driver.find_element(By.CSS_SELECTOR, "#userA")
# 输入用户名
element.send_keys("admin1")
# 删除1   send_keys(Keys.BACK_SPACE) 删除键(BackSpace)
element.send_keys(Keys.BACK_SPACE)
# 全选    send_keys(Keys.CONTROL,'a') 全选(Ctrl+A)
element.send_keys(Keys.CONTROL, 'a')
# 复制    send_keys(Keys.CONTROL,'c') 复制(Ctrl+C)
element.send_keys(Keys.CONTROL, 'c')
# 粘贴
driver.find_element(By.CSS_SELECTOR, '#passwordA').send_keys(Keys.CONTROL, 'v')